package org.example.casemodule.controller;

import org.example.casemodule.dto.*;
import org.example.casemodule.service.ILawyerService;
import org.example.common.config.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/lawyer")
public class LawyerController {
    @Autowired
    private ILawyerService lawyerService;

    //律师资质审核
    @PostMapping("/audit")
    public Result audit(@RequestBody AuditDTO auditDTO) {
        return Result.ok(lawyerService.lawyerAudit(auditDTO.getLawyerId(), auditDTO.getStatus(), auditDTO.getEffectiveDate()));
    }

    @GetMapping("/info/{lawyerId}")
    public Result getLawyerInfo(@PathVariable Long lawyerId) {
        return Result.ok(lawyerService.getLawyerInfo(lawyerId));
    }

    //律师绩效评估
    @GetMapping("/performance")
    public Result getLawyerPerformance(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date period,
                                      @RequestParam List<Long> lawyerId) {
        return Result.ok(lawyerService.getLawyerPerformance(period, lawyerId));
    }

    @PostMapping("/assign")
    public Result getAssign(@RequestBody AssignDTO assignDTO) {
        return Result.ok(lawyerService.getAssign(assignDTO));
    }

    //律师状态管理
    @PutMapping("/status")
    public Result updateStatus(@RequestBody LawyerStatusDTO lawyerStatusDTO) {
        return Result.ok(lawyerService.updateStatus(lawyerStatusDTO));
    }

    //律师检索
    @GetMapping("/search")
    public Result search(@RequestParam List<String> practiceAreas,
                         @RequestParam Double minRating,
                         @RequestParam Integer maxWorkload,
                         @RequestParam Double minSuccessRate,
                         @RequestParam String location) {
        return Result.ok(lawyerService.getLawyerSearch(practiceAreas, minRating, maxWorkload, minSuccessRate, location));
    }

    //律师档案管理
    @GetMapping("/profile")
    public Result getLawyerProfile() {
        return Result.ok(lawyerService.getLawyerProfile());
    }

    //律师档案编辑
    @PutMapping("/profile")
    public Result updateLawyerProfile(@RequestBody LawyerProfileDTO lawyerProfileDTO) {
        return Result.ok(lawyerService.updateLawyerProfile(lawyerProfileDTO));
    }

    //获取律师资质证书
    @GetMapping("/certificates")
    public Result getLawyerCertificates() {
        return Result.ok(lawyerService.getLawyerCertificates());
    }
    //律师资质证书上传
    @PostMapping("/certificates")
    public Result updateLawyerCertificates(@RequestBody CertificatesDTO certificatesDTO) {
        return Result.ok(lawyerService.updateLawyerCertificates(certificatesDTO));
    }
    //律师资质证书删除
    @DeleteMapping("/certificates/{Id}")
    public Result deleteLawyerCertificates(@PathVariable Long Id) {
        return Result.ok(lawyerService.deleteLawyerCertificates(Id));
    }

    //获取服务领域
    @GetMapping("/expertise")
    public Result getExpertise() {
        return Result.ok(lawyerService.getExpertise());
    }
    //设置律师服务领域
    @PutMapping("/expertise")
    public Result setExpertise(@RequestBody ExpertiseDTO expertiseDTO) {
        return Result.ok(lawyerService.setExpertise(expertiseDTO));
    }

    //服务评价

    /**
     * URL: GET /api/lawyer/ratings ​请求参数:
     *
     * page: 页码 (默认1)
     * size: 每页数量 (默认10)
     * sort: 排序 (默认date_desc)
     * @param page
     * @param size
     * @param sort
     * @return
     */
    @GetMapping("/ratings")
    public Result getLawyerRatings(@RequestParam Long page,
                                   @RequestParam Long size,
                                   @RequestParam String sort){
        return Result.ok(lawyerService.getLawyerRatings(page,size,sort));
    }

    //获取律师接案偏好
    @GetMapping("/preference")
    public Result getLawyerPreference(){
        return Result.ok(lawyerService.getLawyerPreference());
    }

    //设置律师接案偏好
    @PutMapping("/preference")
    public Result setLawyerPreference(@RequestBody LawyerPreferenceDTO lawyerPreferenceDTO){
        return Result.ok(lawyerService.setLawyerPreference(lawyerPreferenceDTO));
    }

   //资料审核状态
    @GetMapping("/audit-status")
    public Result getAuditStatus(){
        return Result.ok(lawyerService.getAuditStatus());
    }

    //获取服务时间
    @GetMapping("/schedule")
    public Result getSchedule(){
        return Result.ok(lawyerService.getSchedule());
    }

}
